package com.my.netty;

import com.my.netty.util.Const;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.pool.AbstractChannelPoolMap;
import io.netty.channel.pool.ChannelPoolMap;
import io.netty.channel.pool.FixedChannelPool;
import io.netty.channel.pool.SimpleChannelPool;
import io.netty.channel.socket.nio.NioSocketChannel;

import java.net.InetSocketAddress;

public class NettyPoolClient {

    final EventLoopGroup group = new NioEventLoopGroup();
    final Bootstrap strap = new Bootstrap();

    public static ChannelPoolMap<InetSocketAddress, SimpleChannelPool> poolMap;



    public void build() {
        strap.group(group)
                .channel(NioSocketChannel.class);
        poolMap = new AbstractChannelPoolMap<InetSocketAddress, SimpleChannelPool>() {
            @Override
            protected SimpleChannelPool newPool(InetSocketAddress key) {
                System.out.println(key);
                return new FixedChannelPool(strap.remoteAddress(key), new NettyChannelPoolHandler(), 2);
            }
        };
    }


    public static void main(String[] args) {
        NettyPoolClient client = new NettyPoolClient();
        client.build();
     /*   final SimpleChannelPool pool = client.poolMap.get(Const.remoteAddr);
        System.out.println(pool);*/
    }

}
